const app = getApp()
const {viewHeight,Toast} = app.globalData

import {findReportOnLimit} from "../../../../api/report"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    limit:3,
    skip:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    let limit = Math.ceil(viewHeight / 450) 
    // console.log(limit);
    let ret = await findReportOnLimit(limit,0)
    
    if(ret.code == 200){
      this.setData({
        reportList:ret.data,
        skip:this.data.skip + limit
      })
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  async onReachBottom(){
    Toast.loading("加载中...")

    let {skip,limit,reportList} = this.data

    let ret = await findReportOnLimit(limit,skip)
    // console.log(ret);
    if(ret.code == 200){
      if(ret.data.length == 0){
        Toast.fail("没有更多数据啦~")
      }else{
        let newReportList = [...reportList,...ret.data]
        this.setData({
          reportList:newReportList,
          skip:this.data.skip + limit
        })
        Toast.success("加载完成")
      }
    }
  }
})